<template>
  <div class="Analyze-Layers">
    <div class="layer-title">
      <div class="title">设备图层</div>
      <el-icon class="close-icon" @click="emit('close')">
        <Close />
      </el-icon>
    </div>
    <el-scrollbar max-height="600px">
      <div class="station-item" v-for="(item, index) in legend" :key="index">
        <img class="station-item-icon-box" :src="item.url" v-if="item.url" />
        <template v-else-if="item.color">
          <div class="station-item-checkbox-box">
            <el-checkbox v-model="item.checked" @change="addOrRemove(item.type)"></el-checkbox>
            <div class="station-item-color-box" :style="{ background: item.color }"></div>
          </div>
        </template>
        <div class="station-item-font-box">{{ item.name }}</div>
      </div>
    </el-scrollbar>
  </div>
</template>

<script setup lang="ts">
interface LegendItem {
  url?: string;
  color?: string;
  checked?: boolean;
  type?: string;
  name: string;
}
const emit = defineEmits(['addOrRemove', 'close']);
const props = defineProps({
  legend: {
    type: Array as () => LegendItem[],
    required: true
  }
});
const addOrRemove = (type: string) => {
  emit('addOrRemove', type);
};
</script>

<style lang="scss">
.Analyze-Layers {
  position: absolute;
  top: 24%;
  left: 29%;
  padding: 20px;
  box-sizing: border-box;
  z-index: 99;
  color: #fff;
  background-color: rgba($color: #004068, $alpha: 0.6);
  width: 18rem;
  border: 2px solid #045bbd;
  box-shadow: inset 0 0 25px 0 #1b5bfb;
  .layer-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    margin-bottom: 10px;

    .title {
      font-family: PangMenZhengDao;
      font-size: 1.125rem;
    }

    .close-icon {
      cursor: pointer;
    }

    .title:before {
      content: '';
      display: inline-block;
      width: 0.375rem;
      height: 1rem;
      margin-right: 0.25rem;
      background-color: #3ba0ff;
      vertical-align: text-top;
    }
  }
  .station-item {
    position: relative;
    font-family: YouSheBiaoTiHei;
    width: 100%;
    min-height: 1.875rem;
    background: rgba(14, 89, 214, 0.34);
    margin-top: 0.625rem;
    line-height: 1.875rem;
    padding: 0 10px;
    box-sizing: border-box;
    font-size: 1.125rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;

    .station-item-icon-box {
      width: 20px;
      height: 25px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    .station-item-checkbox-box {
      width: 30%;
      height: 25px;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .station-item-color-box {
        width: 20px;
        height: 20px;
      }
    }

    .station-item-font-box {
      color: #00ffff;
      font-family: PangMenZhengDao;
    }
  }

  .el-checkbox__inner {
    border-radius: 0 0 0 0;
    opacity: 1;
    background: transparent;
    border: 1px solid #00ffff;
  }

  .el-tree-node > .el-tree-node__content {
    height: 33px;
    background-color: transparent;
  }

  .el-tree-node > .el-tree-node__content:hover {
    background-color: transparent;
  }

  .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
    background-color: transparent;
  }

  .custom-tree-node {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    display: inline-block;
  }

  .el-tree-node__label {
    margin-left: 9px;
  }

  .el-tree-node__content {
    position: relative;
  }

  .el-tree-node__content:hover .el-tree-node__label {
    overflow: visible;
    position: relative;
    z-index: 1;
  }
}
@media (min-width: 3840px) {
  .Analyze-Layers {
    top: 23%;
    left: 28%;
  }
}
</style>
